package com.blogspot.security.domain;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.blogspot.security.dao.impl.UserRegisterDaoImpl;
import com.blogspot.security.enumtype.Status;

public class ApplicationAuthenticatedUser implements UserDetails {
	private Logger logger = LoggerFactory.getLogger(ApplicationAuthenticatedUser.class);
    private static final long serialVersionUID = 1L;
    private ApplicationUser user;
    
    public ApplicationAuthenticatedUser(ApplicationUser user) {
    	logger.error("---Allan Sung ApplicationAuthenticatedUser");
        if (user == null) {
            throw new IllegalArgumentException("Authenticated User needs a valid user");
        }
        this.user = user;
        
    }
    
	public Collection<? extends GrantedAuthority> getAuthorities() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getPassword() {
		// TODO Auto-generated method stub
		return user.getPassword();
	}

	public String getUsername() {
		// TODO Auto-generated method stub
		return user.getUserName();
	}

	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
        boolean nonExpired = false;
        Status status = user.getStatus();

        switch (status) {
            case A: 
                nonExpired = true;
                break;
            default: 
                break;
        }
        return nonExpired;
	}

	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
        boolean notLocked = false;
        Status status = user.getStatus();

        switch (status) {
            case A:
                notLocked = true;
                break;
            default: 
                break;
        }
        return notLocked;
	}

	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
        boolean notExpired = false;
        Status status = user.getStatus();

        switch (status) {
            case A: 
                notExpired = true;
                break;
            default: 
                break;
        }
        return notExpired;
	}

	public boolean isEnabled() {
		// TODO Auto-generated method stub
        boolean enabled = false;
        Status status = user.getStatus();

        switch (status) {
            case A:
                enabled = true;
                break;
            default: 
                break;
        }
        return enabled;
	}
}
